package com.ktjy.springredis.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktjy.springredis.entity.Role;
import com.ktjy.springredis.entity.User;
import com.ktjy.springredis.mapper.RoleMapper;
import com.ktjy.springredis.service.IRoleService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @return 13141
 * 2025/7/14
 * 17:12
 */
@Service("roleService")
public class RoleServiceImpl implements IRoleService {
    private static final Logger LOGGER = LoggerFactory.getLogger(RoleServiceImpl.class);
    @Resource
    private RoleMapper roleMapper;
    @Override
    public int insert(Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int delete(Long id) {
        return roleMapper.delete(id);
    }

    @Override
    public int update(Role role) {
        return roleMapper.updateById(role);
    }

    @Override
    @Cacheable(value = "role", key = "#id")
    public Role get(Long id) {
        return roleMapper.get(id);
    }

    @Override
    public List<Role> findAllRoles() {
        return roleMapper.selectList(null);
    }

    @Override
    public IPage<Role> getRoleByPage(HashMap<String, Object> hashMap) {
        Integer pageNo = (Integer) hashMap.get("pageIndex");
        Integer pageSize = (Integer) hashMap.get("pageSize");
        Page<Role> page = new Page<>(pageNo, pageSize);
        IPage<Role> roleIPage = roleMapper.getRoleByPage(page, hashMap);
        return roleIPage;
    }
}
